import { getChannelsAPI } from '../../api/channel';
import { CHANNEL_SAVE_LIST, CHANNEL_UPDATE_ID } from './actionType';

// 2. 封装异步 action
export const getChannelsAction = () => {
  return async (dispatch) => {
    const res = await getChannelsAPI();
    // console.log('res -----> ', res);
    // 2. dispatch 触发 action
    dispatch({ type: CHANNEL_SAVE_LIST, payload: res.data.channels });
  };
};

export const updateIdAction = (id) => {
  return {
    type: CHANNEL_UPDATE_ID,
    payload: id,
  };
};
